  
global PathData = "~/Dropbox/FATA_fractionalization/1_Data/"
global PathRes = "~/Dropbox/FATA_fractionalization/4_Results/"

use "${PathData}fata_data_recoded_max.dta", clear

encode vill_code, gen(vill_code_enc)

gen count = 1
bys vill_code_enc: egen vill_pop = sum(count) 
bys vill_code_enc tribe_rel: egen tribe_pop = sum(count)


tab tribe_rel, gen(tribe)
foreach var of varlist tribe1-tribe87 {
replace `var' = tribe_pop if `var'!=0
}

seg tribe1-tribe87 , c  by(tehs_code) u(vill_code_enc) file("${PathData}tehs_segr.dta") replace sampcounts tsize(vill_pop) 


********
  
global PathData = "~/Dropbox/FATA_fractionalization/1_Data/"
global PathRes = "~/Dropbox/FATA_fractionalization/4_Results/"

use "${PathData}fata_data_min_recoded.dta", clear

gen count = 1
bys vill_code: egen vill_pop = sum(count) 
bys vill_code tribe: egen tribe_pop = sum(count)


tab tribe_name, gen(tribe)
foreach var of varlist tribe1-tribe21 {
replace `var' = tribe_pop if `var'!=0
}

seg tribe1-tribe21 , c  by(tehs_code) u(vill_code) file("${PathData}tehs_segr_min.dta") replace sampcounts tsize(vill_pop) 

